package org.ricks.net.action.context.head;

import java.nio.ByteBuffer;

public interface HeadMeta {
    // 优化4: 消除魔法数字
    int MAX_HEADER_SIZE = 16;
    byte FLAG_RPC = (byte) 0x80;
    byte FLAG_RESPONSE = 0x40;
    byte FLAG_HEARTBEAT = 0x20;

    int cmd();

    // 优化5: 使用ByteBuffer避免重复分配
    ByteBuffer generateHeader(ByteBuffer buffer);

    // 默认方法实现
    default boolean isRpc() {
        return (flags() & FLAG_RPC) != 0;
    }

    default boolean isRpcResponse() {
        return isRpc() && (flags() & FLAG_RESPONSE) != 0;
    }

    default boolean isHeartbeat() {
        return (flags() & FLAG_HEARTBEAT) != 0;
    }


    default int rpcRequestId() {
        return 0;
    }

    default byte flags() {
        return 0;
    }

    default int headSize () {
        return 2;
    }
}
